//
//  HYSecurityManager.m
//  JFBase
//
//  Created by Sunline on 2018/11/12.
//  Copyright © 2018 Alan Wang. All rights reserved.
//

#import "HYSecurityManager.h"
#import "NSString+HYUtil.h"

@implementation HYSecurityManager

+ (NSString *)signWithParameterMd5:(NSMutableDictionary *)parameterDic WithKey:(NSString *)key{
    if (!parameterDic) {
        return @"";
    }
    if ([[parameterDic allKeys] containsObject: @"sign"]){
        [parameterDic removeObjectForKey:@"sign"];
    }
    
    NSArray *array = [parameterDic allKeys];
    
    array = [array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
        NSComparisonResult result = [obj1 compare:obj2];
        return result == NSOrderedDescending;
    }];
    
    
    NSString *assemblageStr = @"";
    for (int i = 0; i < array.count; i++) {
        NSString *key = [NSString stringWithFormat:@"%@",[array objectAtIndex:i]];
        NSString *value = [parameterDic objectForKey:key];
        assemblageStr = [assemblageStr stringByAppendingFormat:@"%@",[NSString stringWithFormat:@"%@%@",key,value]];
    }
    assemblageStr = [assemblageStr stringByAppendingFormat:@"%@",key];
    
    NSString *tempMd5 = [assemblageStr md5];
    
    return tempMd5;
}

@end
